package social.hub.oauth;

import social.hub.oauth.jersey.JerseyServiceProvider;
import social.hub.oauth.oauth4j.OAuth4JServiceProvider;
import social.hub.oauth.scribe.ScribeServiceProvider;

public class OAuthServiceProviderFactory {

	private static OAuthServiceProviderFactory INSTANCE = new OAuthServiceProviderFactory();

	public static OAuthServiceProviderFactory getInstance() {
		return INSTANCE;
	}

	private OAuthProviderType defaultType = OAuthProviderType.JERSEY;

	public OAuthServiceProvider getServiceProvider(OAuthServiceConfig serviceConfig) {
		return getServiceProvider(serviceConfig, defaultType);
	}

	public OAuthServiceProvider getServiceProvider(OAuthServiceConfig serviceConfig, OAuthProviderType type) {

		OAuthServiceProvider result = null;

		switch (type) {
		case JERSEY:
			result = new JerseyServiceProvider(serviceConfig);
			break;
		case SCRIBE:
			result = new ScribeServiceProvider(serviceConfig);
			break;
		case OAUTH4J:
			result = new OAuth4JServiceProvider(serviceConfig);
			break;
		}

		return result;

	}

	public void setDefaultType(OAuthProviderType defaultType) {
		this.defaultType = defaultType;
	}

}
